/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.client.control;


import com.edu.kamai.webservice.client.WSPaperAnswerClient;
import com.edu.kamai.webservice.paperanswer.PaperAnswer;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author xyzhu
 */
public class paperAnswerControl {
    private static List<String> netList;
    private static String message;
    private static WSPaperAnswerClient wsPaperAnswerClient;

    public static String getMessage() {
        return message;
    }

    public static void setMessage(String message) {
        paperAnswerControl.message = message;
    }

    public static List<String> getNetList() {
        return netList;
    }

    public static void setNetList(List<String> netList) {
        paperAnswerControl.netList = netList;
    }
    
    public static void setServer(){
        try{
            wsPaperAnswerClient = new WSPaperAnswerClient();
            
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
    
    public static int addPaperAnswer(int paperRole,String paperPath,
            int finishTime,int paperId,String userId,int contestId){
        int ans;
        
        try{
            ans = wsPaperAnswerClient.addPaperAnswer(paperRole, paperPath, 
                    finishTime, paperId, userId, contestId);
            if (ans == 1) {
                message = "Add Paper Answer OK!";
            } else {
                message = "Add Paper Answer Failed!";
            }
            
        }catch(Exception ex){
            ans = 0;
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
    
        return ans;

    }
    
    public static List<PaperAnswer> checkPendingAnswer(){
        List<PaperAnswer> pending = null;
        try{
            pending = wsPaperAnswerClient.checkPendingAnswer();
            if(null == pending){
                pending = new ArrayList<PaperAnswer>();
                message = "Check Pending Answer : null"; 
            }else if(0 == pending.size()){
                message = "Check Pending Answer : 0"; 
            }else{
                message = "Check Pending Answer : OK"; 
            }
            return pending;
        }catch(Exception ex){
            message = "Connect Server Error!";
            return null;
        }
    }
    
    public static PaperAnswer getAnswerPaperByID(int aid){
        PaperAnswer pa = null;
        try{
            pa = wsPaperAnswerClient.getAnswerPaperByID(aid);
            if(null == pa){
                message = "get Paper Answer : null"; 
            }else{
                message = "Check Pending Answer : OK"; 
            }
            return pa;
        }catch(Exception ex){
            message = "Connect Server Error!";
            return null;
        }
    }
    
    public static int updateSocre(int aid,String teacherName,int socre){
        int ans = 0;
        try{
            ans = wsPaperAnswerClient.updateScore(aid, teacherName, socre);
            if (ans == 1) {
                message = "Update Socre OK!";
            } else {
                message = "Update Socre Failed!";
            }
            return ans;
        }catch(Exception ex){
            message = "Connect Server Error!";
            return 0;
        }
    }
    
    public static List<PaperAnswer> getAnswerScoreByContestIDAndUserID(int cid,
            String uid){
        List<PaperAnswer> answerscore = null;
        try{
            answerscore = wsPaperAnswerClient.getAnswerScoreByContestIDAndUserID
                    (cid, uid);
            if(null == answerscore){
                answerscore = new ArrayList<PaperAnswer>();
                message = "Check Pending Answer : null"; 
            }else if(0 == answerscore.size()){
                message = "Check Pending Answer : 0"; 
            }else{
                message = "Check Pending Answer : OK"; 
            }
            return answerscore;
        }catch(Exception ex){
            message = "Connect Server Error!";
            return null;
        }
    }
    
    
}
